#include   <stdio.h> 
#include   <stdlib.h> 
#include   <pthread.h> 
#include   <unistd.h> 
#include <errno.h>

void * func(void* arg) 
{ 
//	pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, NULL );
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,   NULL);   

	printf( "%d\n", errno );
	while   (1)     
	{
	} 
	return   NULL; 
} 

int   main(int   argc,   char   *argv[]) 
{ 
	pthread_t   thrd; 
	pthread_attr_t   attr; 
	pthread_attr_init(&attr); 
	pthread_attr_setdetachstate(&attr,   PTHREAD_CREATE_DETACHED); 

	if   (   pthread_create(&thrd,   &attr,   func,   NULL)   ) 
	{ 
		perror( "pthread_create   error "); 
		exit(EXIT_FAILURE); 
	} 

	//pthread_join( thrd, NULL );

	if   (  0 ==  pthread_cancel(thrd)   ) 
	{ 
		printf(   "pthread_cancel   OK\n "   ); 
	} 

	sleep(   10   ); 
	return   0; 
} 
